package huawei.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.AccessibilityDelegate;
import android.view.ViewGroup.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.LinearInterpolator;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.widget.TextViewCompat;
import o.fkr$d;
import o.fkr$g;
import o.fkr$i;
import o.fkr.c;
import o.fpx;
import o.fqb;

public class HwErrorTipTextLayout extends LinearLayout {
    private int ʻ;
    private int ʼ;
    private int ʽ;
    private TextView ˊ;
    private boolean ˋ;
    private int ˎ;
    private EditText ˏ;
    private fpx ॱ;
    private int ᐝ;

    class d extends AccessibilityDelegate {
        final /* synthetic */ HwErrorTipTextLayout ॱ;

        private d(HwErrorTipTextLayout hwErrorTipTextLayout) {
            this.ॱ = hwErrorTipTextLayout;
        }

        public void onInitializeAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
            super.onInitializeAccessibilityEvent(view, accessibilityEvent);
            accessibilityEvent.setClassName(HwErrorTipTextLayout.class.getSimpleName());
        }

        public void onPopulateAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
            super.onPopulateAccessibilityEvent(view, accessibilityEvent);
        }
    }

    public HwErrorTipTextLayout(Context context) {
        this(context, null);
    }

    public HwErrorTipTextLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, fkr$d.ˋ);
    }

    public HwErrorTipTextLayout(Context context, AttributeSet attributeSet, int i) {
        super(fqb.ˋ(context), attributeSet, i);
        ˊ(super.getContext(), attributeSet, i);
    }

    private void ˊ(Context context, AttributeSet attributeSet, int i) {
        setOrientation(1);
        setAddStatesFromChildren(true);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, fkr$i.ॱˋ, i, fkr$g.ˎ);
        this.ʼ = obtainStyledAttributes.getResourceId(fkr$i.ॱˎ, 0);
        this.ʽ = obtainStyledAttributes.getResourceId(fkr$i.ʽॱ, 0);
        this.ᐝ = obtainStyledAttributes.getResourceId(fkr$i.ʻॱ, 0);
        this.ˎ = obtainStyledAttributes.getResourceId(fkr$i.ʿ, 0);
        this.ʻ = obtainStyledAttributes.getResourceId(fkr$i.ॱᐝ, 0);
        this.ˋ = obtainStyledAttributes.getBoolean(fkr$i.ʼॱ, true);
        this.ॱ = fpx.values()[obtainStyledAttributes.getInt(fkr$i.ˈ, 0)];
        obtainStyledAttributes.recycle();
        setAccessibilityDelegate(new d());
    }

    public void addView(View view, int i, LayoutParams layoutParams) {
        if (view instanceof EditText) {
            ˊ((EditText) view);
            if (this.ॱ == fpx.LINEAR) {
                View linearLayout = new LinearLayout(getContext());
                linearLayout.setGravity(16);
                linearLayout.setMinimumHeight(getResources().getDimensionPixelSize(c.ˊ));
                linearLayout.addView(view, ˏ(layoutParams));
                super.addView(linearLayout, 0);
                return;
            }
            super.addView(view, 0, ˏ(layoutParams));
            return;
        }
        super.addView(view, i, layoutParams);
    }

    private void ˊ(EditText editText) {
        if (this.ˏ != null) {
            throw new IllegalArgumentException("We already have an EditText, can only have one");
        }
        this.ˏ = editText;
        this.ˏ.setImeOptions(this.ˏ.getImeOptions() | 33554432);
        if (this.ॱ == fpx.BUBBLE) {
            this.ˏ.setBackgroundResource(this.ʼ);
        } else {
            this.ˏ.setBackgroundResource(this.ʽ);
        }
        ˋ();
    }

    private LinearLayout.LayoutParams ˏ(LayoutParams layoutParams) {
        return new LinearLayout.LayoutParams(layoutParams);
    }

    public void setHint(CharSequence charSequence) {
        if (this.ˏ != null) {
            this.ˏ.setHint(charSequence);
            sendAccessibilityEvent(2048);
        }
    }

    public void setErrorEnabled(boolean z) {
        if (z != this.ˋ && this.ˊ != null) {
            this.ˊ.setAlpha(z ? 1.0f : 0.0f);
            this.ˊ.setVisibility(z ? 0 : 8);
            this.ˋ = z;
        }
    }

    private void ˋ() {
        int i;
        this.ˊ = new TextView(getContext());
        this.ˊ.setVisibility(8);
        if (this.ॱ == fpx.LINEAR) {
            i = 0;
        } else {
            i = getResources().getDimensionPixelSize(c.ˏ);
        }
        this.ˊ.setPaddingRelative(this.ˏ.getPaddingLeft(), i, this.ˏ.getPaddingRight(), 0);
        TextViewCompat.ˎ(this.ˊ, this.ˎ);
        addView(this.ˊ);
    }

    private void ˏ(boolean z) {
        if (this.ˏ != null && this.ˊ != null) {
            if (this.ॱ == fpx.BUBBLE) {
                this.ˏ.setBackgroundResource(z ? this.ᐝ : this.ʼ);
            } else {
                this.ˏ.setBackgroundResource(z ? this.ʻ : this.ʽ);
            }
        }
    }

    public void setError(CharSequence charSequence) {
        if (this.ˏ != null && this.ˊ != null && this.ˋ) {
            final boolean z = !TextUtils.isEmpty(charSequence);
            this.ˊ.setText(charSequence);
            this.ˊ.animate().setInterpolator(new LinearInterpolator()).setDuration(200).alpha(z ? 1.0f : 0.0f).setListener(new AnimatorListenerAdapter(this) {
                final /* synthetic */ HwErrorTipTextLayout ˎ;

                public void onAnimationEnd(Animator animator) {
                    super.onAnimationEnd(animator);
                    this.ˎ.ˏ(z);
                    this.ˎ.ˊ.setAlpha(z ? 1.0f : 0.0f);
                    this.ˎ.ˊ.setVisibility(z ? 0 : 8);
                }
            }).start();
            sendAccessibilityEvent(2048);
        }
    }
}
